package com.learing.groupChat.handler;

import com.learing.groupChat.packet.LogoutRequestPacket;
import com.learing.groupChat.packet.LogoutResponsePacket;
import com.learing.utils.SessionUtil;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * 登出请求
 */
@ChannelHandler.Sharable
public class LogoutRequestHandler4Single extends SimpleChannelInboundHandler<LogoutRequestPacket> {
    // 2. 构造单例
    public static final LogoutRequestHandler4Single INSTANCE = new LogoutRequestHandler4Single();

    protected LogoutRequestHandler4Single(){

    }
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, LogoutRequestPacket msg) {
        SessionUtil.unBindSession(ctx.channel());
        LogoutResponsePacket logoutResponsePacket = new LogoutResponsePacket();
        logoutResponsePacket.setSuccess(true);
        ctx.channel().writeAndFlush(logoutResponsePacket);
    }
}
